package belf.migrate.api.util;

import org.apache.commons.lang3.StringUtils;

import java.util.List;
import java.util.function.Predicate;

public class TableNameComparator {
    public static boolean containsTable(List<String> tables, String sinkTable) {
        return tables.stream().anyMatch(new Predicate<String>() {
            @Override
            public boolean test(String fullTableName) {
                String simpleName = fullTableName;
                if (fullTableName.contains(".")) {
                    simpleName = StringUtils.substringAfterLast(fullTableName, ".");
                }
                return simpleName.equalsIgnoreCase(sinkTable);
            }
        });

    }

    public static boolean containsDatabase(List<String> dadtabases, String sinkDatabase) {
        return dadtabases.stream().anyMatch(new Predicate<String>() {
            @Override
            public boolean test(String database) {
                return database.equalsIgnoreCase(sinkDatabase);
            }
        });

    }
}
